package com.liumingtai.demo01.email.controller;

import com.liumingtai.demo01.common.utils.R;
import com.liumingtai.demo01.email.config.WebConfigProperties;
import com.liumingtai.demo01.email.dto.EmailDto;
import com.liumingtai.demo01.email.utils.SendByEmailUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Description;
import org.springframework.web.bind.annotation.*;

@RestController
@RefreshScope
@RequestMapping("/email")
public class EmailController {

    @Autowired
    WebConfigProperties webConfigProperties;
    @Autowired
    SendByEmailUtils sendByEmailUtils;


    @GetMapping(" ")
    public String index() {
        return "hello, email there";
    }


    @GetMapping("/configTest")
    public String config1() {
        return webConfigProperties.getDesc();
    }


    @PostMapping("/send")
    @ResponseBody
    @Description("request参数：" +
            "{\n" +
            "\t\"receiver\":\"1352983234@qq.com\",\n" +
            "\t\"title\":\"发送邮箱测试\",\n" +
            "\t\"text\":\"你好 邮箱\"\n" +
            "\t\n" +
            "}")
    public R sendEmail(@RequestBody EmailDto emailDto) {
        emailDto.setSender("liumingtai@coolgua.com");
        sendByEmailUtils.send(emailDto.getSender(), emailDto.getReceiver(), emailDto.getTitle(), emailDto.getText());
        return R.ok("发送成功");
    }

}
